package com.xinke.module.system.mapper.user;

import java.util.*;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xinke.component.common.pojo.PageResult;
import com.xinke.component.mybatis.mybatis.core.query.LambdaQueryWrapperExt;
import com.xinke.component.mybatis.mybatis.core.mapper.BaseMapperExt;
import com.xinke.module.system.model.entity.user.UserPostDO;
import org.apache.ibatis.annotations.Mapper;
import com.xinke.module.system.model.vo.user.*;

/**
 * 用户和岗位关联 Mapper
 *
 * @author yzx
 */
@Mapper
public interface UserPostMapper extends BaseMapperExt<UserPostDO> {

    default PageResult<UserPostDO> selectPage(UserPostPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperExt<UserPostDO>()
                .eqIfPresent(UserPostDO::getUserId, reqVO.getUserId())
                .eqIfPresent(UserPostDO::getPostId, reqVO.getPostId())
                .orderByDesc(UserPostDO::getUserPostId));
    }

    default List<UserPostDO> selectListByUserId(Long userId) {
        return selectList(UserPostDO::getUserId, userId);
    }

    default void deleteByUserIdAndPostId(Long userId, Collection<Long> postIds) {
        delete(new LambdaQueryWrapperExt<UserPostDO>()
                .eq(UserPostDO::getUserId, userId)
                .in(UserPostDO::getPostId, postIds));
    }

    default void deleteByUserId(Long userId) {
        delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId));
    }
}